package effectiveJava.myEnum;

/**
 * Created by dycong on 2017/9/4.
 *todo  对少数常量采用方法覆盖的方式
 */
public enum PayrollDay2 {
    MONDAY,
    TUESDAY,
    WEDNESDAY,
    THURSDAY,
    FRIDAY,
    SATURDAY {
        @Override
        public double pay(double hoursWorked, double payRate) {
            double base = hoursWorked * payRate;
            double overtimePay = overtimePay = hoursWorked * payRate / 2;
            return base + overtimePay;
        }
    },
    SUNDAY {
        @Override
        public double pay(double hoursWorked, double payRate) {
            double base = hoursWorked * payRate;
            double overtimePay = overtimePay = hoursWorked * payRate / 2;
            return base + overtimePay;
        }
    };

    private static final int HOURS_PER_SHIFT = 8;

    /*todo 默认的工作日计算方法*/
    public double pay(double hoursWorked, double payRate) {
        double base = hoursWorked * payRate;
        double overtimePay = hoursWorked <= HOURS_PER_SHIFT ? 0 : (hoursWorked - HOURS_PER_SHIFT) / 2;
        return base + overtimePay;
    }

/*todo 从维护角度来看这种写法比较危险的，添加新的节假日时，如果没有修改覆盖pay()方法语句，工资会算错*/
}
